package com.bj58.ecdata.mailreport.util;

import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import javax.mail.Multipart;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMultipart;
@SuppressWarnings("rawtypes")
public class MailForJMail {

    public final static int HTML_MAIL = 1;
    public final static int TEXT_MAIL = 2;
    private String subject;
    private String from;
    private List<String> tolist = new LinkedList<String>();
    private List<String> copyToList = new LinkedList<String>();
    private int MailType;
    private Multipart multipart = new MimeMultipart();
    private String content = null;
    private String ccusers = null;
	private ArrayList attachedFileList = null;
    private Date date = null;

    public MailForJMail() {
        // TODO Auto-generated constructor stub
    }

    public ArrayList getAttachedFileList() {
        return attachedFileList;
    }

    public void setAttachedFileList(ArrayList attachedFileList) {
        this.attachedFileList = attachedFileList;
    }

    public void addBody(String content, int mailType) {
        if (mailType == HTML_MAIL) {
            addHtmlBody(content);
        } else {
            addTextBody(content);
        }
    }

    private void addHtmlBody(String content) {
        try {
            MimeBodyPart mimeBodyPart = new MimeBodyPart();
            content = "<meta http-equiv=Content-Type content=text/html; charset=GB2312>" + content;
            mimeBodyPart.setContent(content, "text/html;charset=GBK");
            multipart.addBodyPart(mimeBodyPart);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void addTextBody(String content) {
        try {
            MimeBodyPart mimeBodyPart = new MimeBodyPart();
            mimeBodyPart.setText(content);
            mimeBodyPart.setContent(content, "text/html;charset=gbk");//
            multipart.addBodyPart(mimeBodyPart);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void addTo(String mailAddress) {
        this.tolist.add(mailAddress);
    }

    public void addCopyTo(String mailAddress) {
        this.copyToList.add(mailAddress);
    }

    public String getFrom() {
        return from;
    }

    public void setFrom(String from) {
        this.from = from;
    }

    public int getMailType() {
        return MailType;
    }

    public void setMailType(int mailType) {
        MailType = mailType;
    }

    public String getSubject() {
        return subject;
    }

    public void setSubject(String subject) {
        this.subject = subject;
    }

    public Multipart getMultipart() {
        return multipart;
    }

    public void setMultipart(Multipart multipart) {
        this.multipart = multipart;
    }

    public List getCopyTolist() {
        return copyToList;
    }

    @SuppressWarnings("unchecked")
	public void setCopyToList(List copyToList) {
        this.copyToList = copyToList;
    }

    public List getTolist() {
        return tolist;
    }
    @SuppressWarnings("unchecked")
	public void setTolist(List tolist) {
        this.tolist = tolist;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getContent() {
        return content;
    }

    public void setCcusers(String ccusers) {
        this.ccusers = ccusers;
    }

    public String getCcusers() {
        return ccusers;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    public Date getDate() {
        return date;
    }
}

